<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
    <div class="content">
        <div class="panel panel-default panel-intro">

            <div class="panel-body">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in" id="one">
                        <div class="widget-body no-padding">

                            <div class="bootstrap-table">
                                <div class="commonsearch-table ">
                                    <fieldset>
                                        <div class="row">

                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="c-storehouse_id" class="control-label col-xs-4">出库仓库</label>
                                                <div class="col-xs-8">
                                                    {if condition="$admin['storehouse_id'] > 0 "}
                                                    <input type="hidden" name="storehouse_id" value="{$admin['storehouse_id']}">
                                                    <input id="c-storehouse_id" data-rule="required" data-source="data/storehouse/index" data-field="name" class="form-control selectpage"  type="text" value="{$row.storehouse_id}" disabled>
                                                    {else /}
                                                    <input id="c-storehouse_id" data-rule="required" data-source="data/storehouse/index" data-field="name" class="form-control selectpage" name="storehouse_id" type="text" value="{$row.storehouse_id}" disabled>
                                                    {/if}
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label  class="control-label col-xs-4">单据类型</label>
                                                <div class="col-xs-8">
                                                    <select name="type" id=""  class="form-control" disabled>
                                                        <option value="1" {if condition="$row['type'] == 1"} selected {else /}{/if}>报损单</option>
                                                        <option value="2" {if condition="$row['type'] == 2"} selected {else /}{/if}>报溢单</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3 supplier_id"  {if condition="$row.type eq 1 "} {else /}style="display: none"{/if} >
                                                <label  class="control-label col-xs-4">供应商</label>
                                                <div class="col-xs-8">
                                                    <select name="supplier_id" id="" class="form-control" disabled>
                                                        <option value="0">请选择</option>
                                                        {volist name="suppliers" id="vo"}
                                                            <option value="{$vo.id}" {if condition="$row.obj_id eq $vo.id "} selected {else /}{/if}>{$vo.nickname}</option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3 customer_id" {if condition="$row.type eq 2 "} {else /}style="display: none"{/if}>
                                                <label  class="control-label col-xs-4">客户</label>
                                                <div class="col-xs-8">
                                                    <select name="customer_id" id="customer_id" class="form-control" disabled>
                                                        <option value="0">请选择</option>
                                                        {volist name="customers" id="vo"}
                                                            <option value="{$vo.id}" {if condition="$row.obj_id eq $vo.id "} selected {else /}{/if}>{$vo.company}</option>
                                                        {/volist}
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="explain" class="control-label col-xs-4">说明</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="explain" value="{$row.explain}" placeholder="说明" id="explain" data-index="13" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="operator" class="control-label col-xs-4">经手人</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="operator"  placeholder="经手人" id="operator" data-index="6" value="{$row.operator}" disabled>
                                                </div>
                                            </div>
                                            <div class="form-group col-xs-12 col-sm-6 col-md-4 col-lg-3">
                                                <label for="company" class="control-label col-xs-4">部门单位</label>
                                                <div class="col-xs-8">
                                                    <input type="text" class="form-control" name="company"  placeholder="部门单位" id="company" data-index="7" value="{$row.company}" disabled>
                                                </div>
                                            </div>
                                        </div>
                                </div>
                                </fieldset>
                            </div>
                        </div>


<!--                        <div class="fixed-table-toolbar"><div class="bs-bars pull-left"><div id="toolbar" class="toolbar" style="position: relative;">-->
<!--                            <a href="javascript:;" class="btn btn-success btn-add " title="添加"><i class="fa fa-plus"></i> 添加</a>-->
<!--                        </div>-->
                        </div><div class="columns-right pull-right" style="margin-top:10px;margin-bottom:10px;">
                        </div>
                            <table id="table" class="table table-striped table-bordered table-hover table-nowrap"  data-operate-edit="1" data-operate-del="1" width="100%">
                                <thead>
                                    <tr>
                                        <th style="text-align: center; vertical-align: middle; " data-field="id"><div class="th-inner ">Id</div></th>
                                        <!--                                <th style="text-align: center; vertical-align: middle; " data-field="createtime"><div class="th-inner ">出库仓库</div></th>-->
                                        <th style="text-align: center; vertical-align: middle; " ><div class="th-inner ">商品编号</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="number"><div class="th-inner ">商品名称</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="supplier_id"><div class="th-inner ">规格</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operator"><div class="th-inner ">账面库存</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="company"><div class="th-inner ">虚拟库存</div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_goods_total"><div class="th-inner ">调整数量</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="arrival_total"><div class="th-inner ">单位</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">成本价</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="order_price"><div class="th-inner ">成本金额</div><div class="fht-cell"></div></th>
                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">备注</div><div class="fht-cell"></div></th>
<!--                                        <th style="text-align: center; vertical-align: middle; " data-field="operate"><div class="th-inner ">操作</div><div class="fht-cell"></div></th>-->
                                    </tr>
                                </thead>
                                <tbody data-listidx="0" class="connnn" >
                                {volist name="list" id="vo"}
                                        <tr data-index="0"  >
                                            <td class="bs-checkbox ">{$vo.id}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.number}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.title}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.specs}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.stock}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.xstock}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="goods_num">{$vo.goods_num}</td>
                                            <td style="text-align: center; vertical-align: middle; ">{$vo.unit}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.final_cost}</td>
                                            <td style="text-align: center; vertical-align: middle; " class="buy_price">{$vo.final_cost * $vo['goods_num']}</td>
                                            <td style="text-align: center; vertical-align: middle; " >{$vo.remark}</td>
<!--                                            <td style="text-align: center; vertical-align: middle; " >-->
<!--                                            </td>-->
                                        </tr>
                                {/volist}
                                </tbody>

                                <tbody class="tbfoot" data-listidx="0" style="display: ">
                                    <td style="text-align: center; vertical-align: middle; ">合计</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; " class="zstock"></td>
                                    <td style="text-align: center; vertical-align: middle; " class="xstock"></td>
                                    <td style="text-align: center; vertical-align: middle; " class="allnum">0</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                    <td style="text-align: center; vertical-align: middle; " ></td>
                                    <td style="text-align: center; vertical-align: middle; "class="alprice">0</td>
                                    <td style="text-align: center; vertical-align: middle; "></td>
                                </tbody>
                            </table>
                        </div>



                    </div>
                </div>

            </div>
        </div>
    </div>
    <input type="hidden" name="loss_status" value="1" class="loss_status">
    {if condition="$auth->check('stock/loss/examine') && $row.status == 1 "}
        <div class="form-group layer-footer">
            <label class="control-label col-xs-12 col-sm-2"></label>
            <div class="col-xs-12 col-sm-8">
                <button type="submit" class="btn btn-success btn-embossed  subpurchase">{:__('审核通过')}
                </button>
                <input type="submit" class="btn btn-danger btn-embossed  reject" value="驳回">
            </div>
        </div>
    {else /}

    {/if}
</form>

<div class="form-group layer-footer">
    {if condition="$row['status'] == 2 "}
    <div class="col-xs-12 col-sm-3">
        <button type="submit" class="btn btn-danger btn-embossed cancelbill {:$auth->check('stock/loss/cancelbill')?'':'hide'}">{:__('单据红冲')}</button>
    </div>
    {else /}
    {/if}
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
<script>
    $('.subpurchase').click(function (res) {
        $('.loss_status').val(1)
    })
    $('.reject').click(function (res) {
        $('.loss_status').val(3)
    })

    count()
    function count() {
        if($(".connnn > tr").length == 0){
            $('.tbfoot').attr('style','display:none')
            return false;
        }

        var alprice = 0;//销售金额
        var allnum = 0;//销售数量
        var alltax = 0;//税额
        var fare = 0;//税费合计
        var all_cost = 0;//运运费合计


        $('.connnn').find("tr").each(function(){
            var goods_num = $(this).find('.goods_num').html()*1;
            var buy_price = $(this).find('.buy_price').html()*1;
            var tax_all = $(this).find('.tax_all').html()*1;
            // var all_fare = $(this).find('.all_fare').html()*1;
            var ht_price = $(this).find('.ht_price').html()*1;
            allnum= allnum+goods_num
            alprice= buy_price+alprice
            alltax= alltax+tax_all
            // fare= fare+all_fare
            all_cost= all_cost+ht_price

        });
        $('.alprice').html(alprice.toFixed(2))
        $('.allnum').html(allnum)
        $('.alltax').html(alltax.toFixed(2))
        // $('.fare').html(fare)
        $('.all_cost').html(all_cost.toFixed(2))
    }



</script>
{include file='common/adapt' /}